//
//  DDLogWrapper.m
//  JP
//
//  Created by LiaoChenliang on 2022/4/6.
//  Copyright © 2022 LiaoChenliang. All rights reserved.
//

#import "DDLogWrapper.h"
#import "AGNetworkAnalysis.h"
// 定义Log等级
static const DDLogLevel ddLogLevel = DDLogLevelInfo;

@implementation DDLogWrapper

+(void)logError:(NSString *)message{
    DDLogError(@"%@",message);
}
+(void)logWarn:(NSString *)message{
    DDLogWarn(@"%@",message);
}
+(void)logInfo:(NSString *)message{
    DDLogInfo(@"%@",message);
}
+(void)logDebug:(NSString *)message{
    DDLogDebug(@"%@",message);
}
+(void)logVerbose:(NSString *)message{
    DDLogVerbose(@"%@",message);
}


+ (void)addFileLogger:(NSString *)logsDirectory{
    
    DDLogFileManagerDefault *defaultManager = [[DDLogFileManagerDefault alloc] initWithLogsDirectory:logsDirectory];
    DDFileLogger *fileLogger = [[DDFileLogger alloc] initWithLogFileManager:defaultManager];
    
    //重用log文件，不要每次启动都创建新的log文件(默认值是NO)
    fileLogger.doNotReuseLogFiles = YES;
    //log文件在24小时内有效，超过时间创建新log文件 365天有效
    fileLogger.rollingFrequency = 60*60*24*365;
    //禁用文件大小滚动
    fileLogger.maximumFileSize = 0;
    //最多保存1个log文件
    fileLogger.logFileManager.maximumNumberOfLogFiles = 1;
    //log文件夹最多保存1024M
    fileLogger.logFileManager.logFilesDiskQuota = 1024*1024*1024;
    fileLogger.logFormatter = [[self alloc] init];
    [DDLog addLogger:fileLogger];
}

+ (void)removeLogger{
    [DDLog removeAllLoggers];
}

+ (void)addDDOSLogger{
    if (@available(iOS 10.0, *)) {
        [DDLog addLogger:[DDOSLogger sharedInstance]];
    } else {
        // Fallback on earlier versions
    }
}

- (NSString *)formatLogMessage:(DDLogMessage *)logMessage{
    NSString *formatLog = [NSString stringWithFormat:@"%@",logMessage->_message];
    return formatLog;
}
@end
